package team.seekers.oj.course.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.oj.common.annotation.UserSession;
import team.seekers.oj.common.entity.ApiResponseBody;
import team.seekers.oj.common.entity.PageResult;
import team.seekers.oj.common.entity.UserSessionDTO;
import team.seekers.oj.common.enums.ApiExceptionEnum;
import team.seekers.oj.common.util.AssertUtils;
import team.seekers.oj.course.dto.*;
import team.seekers.oj.course.service.CourseManageService;
import team.seekers.oj.group.dto.GroupListDTO;
import team.seekers.oj.group.dto.GroupListReqDTO;

import javax.validation.Valid;


@Controller
@RequestMapping("/manage/course")
public class CourseManageController {

    @Autowired
    private CourseManageService courseManageService;

    @PostMapping("/create")
    @ApiResponseBody
    public Long create(@RequestBody @Valid CourseCreateReqDTO reqDTO) {
        return courseManageService.create(reqDTO);
    }

    @PostMapping("/update")
    @ApiResponseBody
    public Void update(@RequestBody @Valid CourseManageDTO reqDTO) {
        courseManageService.update(reqDTO);
        return null;
    }

    @PostMapping("/page")
    @ApiResponseBody
    public PageResult<CourseListDTO> page(@RequestBody @Valid CourseListReqDTO reqDTO) {
        return courseManageService.page(reqDTO);
    }

    @GetMapping("/delete/{courseId}")
    @ApiResponseBody
    public Void delete(@PathVariable("courseId") Long courseId) {
        courseManageService.delete(courseId);
        return null;
    }

    @GetMapping("/query/{courseId}")
    @ApiResponseBody
    public CourseManageDTO query(@PathVariable("courseId") Long courseId) {
        return courseManageService.query(courseId);
    }

}
